/* parser.h
* libxml++ and this file are copyright (C) 2000 by Ari Johnson, and
* are covered by the GNU Lesser General Public License, which should be
* included with libxml++ as the file COPYING.
*/

#ifndef __LIBXMLPP_PARSER_H
#define __LIBXMLPP_PARSER_H

#ifdef _MSC_VER //Ignore warnings about the Visual C++ Bug, where we can not do anything
#pragma warning (disable : 4786)
#endif

#include "../nodes/element.h"
#include "../exceptions/validity_error.h"
#include "../exceptions/internal_error.h"

#include <istream>

#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C"
{
  struct _xmlParserCtxt;
}
#endif //DOXYGEN_SHOULD_SKIP_THIS

namespace Xml
{
  class ParserSettings;

  /** XML parser.
  *
  */
  class Parser : NonCopyable
  {
  public:
    Parser();
    virtual ~Parser();

    typedef size_t size_type;

    /** Parse an XML document from a file.
    * @throw exception
    * @param filename The path to the file.
    */
    virtual void parse_file(const Glib::ustring& filename,const ParserSettings &settings) = 0;

    /** Parse an XML document from a string.
    * @throw exception
    * @param contents The XML document as a string.
    */
    virtual void parse_memory(const Glib::ustring& contents,const ParserSettings &settings) = 0;

    /** Parse an XML document from a stream.
    * @throw exception
    * @param in The stream.
    */
    virtual void parse_stream(std::istream& in,const ParserSettings &settings) = 0;

  protected:
    virtual void initialize_context(const ParserSettings &settings);
    virtual void release_underlying();

    virtual void on_validity_error(const Glib::ustring& message);
    virtual void on_validity_warning(const Glib::ustring& message);

    virtual void handleException(const Exception& e);
    virtual void check_for_exception();
    virtual void check_for_validity_messages();

    static void callback_validity_error(void* ctx, const char* msg, ...);
    static void callback_validity_warning(void* ctx, const char* msg, ...);

    _xmlParserCtxt* context_;
    Exception* exception_;
    Glib::ustring validate_error_;
    Glib::ustring validate_warning_; //Built gradually - used in an exception at the end of parsing.
  };

} // namespace Xml

#endif //__LIBXMLPP_PARSER_H



